﻿using BankTransfer.Bank.Domain.Exceptions;
using BankTransfer.Bank.Types.Enum;
using BankTransfer.Bank.Types.Types;

namespace BankTransfer.Bank.Domain.Domain.Entity
{
    public class Account
    {
        public AccountId Id { get; private set; }
        public AccountNumber AccountNumber { get; private set; }
        public UserId UserId { get; private set; }
        public Money Available { get; private set; }
        public Money DailyLimit { get; private set; }
        public Currency Currency => Available.Currency;

        /// <summary>
        /// 转出
        /// </summary>
        public void Withdraw(Money money)
        {
            if (Available.CompareTo(money) < 0)
            {
                throw new InsufficientFundsException();
            }
            if (DailyLimit.CompareTo(money) < 0)
            {
                throw new DailyLimitExceededException();
            }
            Available = Available.Subtract(money);
        }

        /// <summary>
        /// 转入
        /// </summary>
        public void Deposit(Money money)
        {
            Available = Available.Add(money);
        }
    }
}